package com.skp.plastory;

import java.util.ArrayList;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ListCustomAdapter extends BaseAdapter {
	private static final String LOG_TAG = "ListCustomAdapter";

	Context context;
	LayoutInflater Inflater;

	ArrayList<InfoStory> arrayList = new ArrayList<InfoStory>();

	TextView mTVStoryDate;
	TextView mTVStoryTitle;
	TextView mTVStroyTag1;
	TextView mTVStroyTag2;
	TextView mTVStroyTag3;

	private int layout;

	public ListCustomAdapter(Context context, int layout, ArrayList<InfoStory> arrayList) {
		this.context = context;
		Inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.layout = layout;
		this.arrayList = arrayList;
	}

	@Override
	public int getCount() {
		return arrayList.size();
	}

	@Override
	public Object getItem(int position) {
		return arrayList.get(position).getTitle();
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		final int finalPosition = position;

		if (convertView == null) {
			Log.e(LOG_TAG, "getView - converView is null");
			convertView = Inflater.inflate(layout, parent, false);
		}
		Log.e(LOG_TAG, "getView - converView is null");

		mTVStoryDate = (TextView) convertView.findViewById(R.id.story_row_date);
		mTVStoryTitle = (TextView) convertView.findViewById(R.id.story_row_title);
		mTVStroyTag1 = (TextView) convertView.findViewById(R.id.story_row_tag1);
		mTVStroyTag2 = (TextView) convertView.findViewById(R.id.story_row_tag2);
		mTVStroyTag3 = (TextView) convertView.findViewById(R.id.story_row_tag3);

		/*
		 * mTVStoryDate.setText(arrayList.get(finalPosition).getDate());
		 * mTVStoryTitle.setText(arrayList.get(finalPosition).getTitle());
		 * 
		 * mTVStroyTag1.setText(arrayList.get(finalPosition).getTag1());
		 * mTVStroyTag2.setText(arrayList.get(finalPosition).getTag2());
		 * mTVStroyTag3.setText(arrayList.get(finalPosition).getTag3());
		 */
		mTVStoryDate.setText(arrayList.get(position).getDate());
		mTVStoryTitle.setText(arrayList.get(position).getTitle());

		mTVStroyTag1.setText(arrayList.get(position).getTag1());
		mTVStroyTag2.setText(arrayList.get(position).getTag2());
		mTVStroyTag3.setText(arrayList.get(position).getTag3());

		return convertView;
	}
}
